refactor(user, validators): extract PromoActivationService & simplify password validators#62
Merged
RandomProgramm3r merged 3 commits intomainfrom Jul 23, 2025
Merged
refactor(user, validators): extract PromoActivationService & simplify password validators#62RandomProgramm3r merged 3 commits intomainfrom
RandomProgramm3r merged 3 commits intomainfrom
Conversation
This commit refactors the promo code activation logic by extracting it from the `PromoActivateView` into a dedicated `PromoActivationService`. Key changes: - Created `user/services.py` to house the new service class. - The `PromoActivationService` now encapsulates all business logic for activating a promo code, including: - User targeting validation (age, country). - Promotion active status check. - Anti-fraud system verification. - Atomic issuance of common or unique promo codes. - Introduced a set of custom, specific exceptions (`PromoActivationError`, `TargetingError`, etc.) to provide clearer error feedback to the API client. - The `PromoActivateView` is now significantly simplified, delegating all logic to the service and handling its success or failure responses.
This commit refactors the password validation classes to improve clarity, reduce complexity, and align better with Django conventions. The key changes include: - Removed the `BaseCountPasswordValidator` abstract base class, as it added unnecessary complexity. Each validator is now a self-contained class. - Simplified the logic within each validator, using more direct and efficient methods for character checks (e.g., `isascii()`, `isupper()`). - Renamed validator classes for conciseness (e.g., `ASCIIOnlyPasswordValidator` to `AsciiValidator`). - Improved internationalization and pluralization of error messages by using `ngettext`. - Updated `settings.py` to reflect the new validator class names and their simplified options.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit consolidates and improves core user-related logic by:
PromoActivateViewinto a newPromoActivationServiceinuser/services.py, which now handles:PromoActivationError,TargetingError, etc.) for clearer API error responsesBaseCountPasswordValidatorabstract class in favor of standalone validatorsAsciiValidator,UppercaseValidator)isascii()andisupper()for clarity and performancengettextto enhance internationalized, pluralized error messagessettings.pyto reference new validator names and optionsBoth the view and validator integrations have been streamlined for maintainability and adherence to Django conventions.